/****************************************************
	文件：DomainBase.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/8/28 7:43:30
	功能：规划域基类（框架层）
*****************************************************/

using System.Collections.Generic;

namespace AIFramework.HTN
{
	public class DomainBase
	{
        protected EntityBase mSelf;
        public List<TaskBase> TaskLst;
        protected Dictionary<string, TaskBase> mTaskDict;

        public DomainBase(EntityBase self)
        {
            mSelf = self;
            TaskLst = new List<TaskBase>();
            mTaskDict = new Dictionary<string, TaskBase>();
        }
        public virtual void Reset()
        {
            mSelf = null;
            TaskLst.Clear();
            mTaskDict.Clear();
        }

        public virtual void Build()
        {
        }

        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="task">任务对象</param>
        /// <returns></returns>
        public DomainBase AddTask(TaskBase task)
        {
            TaskLst.Add(task);
            mTaskDict.Add(task.Name, task);
            return this;
        }
        /// <summary>
        /// 移除任务
        /// </summary>
        /// <param name="task">任务对象</param>
        /// <returns></returns>
        public bool RemoveTask(TaskBase task)
        {
            return RemoveTask(task.Name);
        }
        /// <summary>
        /// 移除任务
        /// </summary>
        /// <param name="taskName">任务名称</param>
        /// <returns></returns>
        public bool RemoveTask(string taskName)
        {
            if (mTaskDict.ContainsKey(taskName))
            {
                mTaskDict.Remove(taskName);
                return true;
            }
            return false;
        }
        /// <summary>
        /// 搜索任务
        /// </summary>
        /// <param name="taskName">任务名称</param>
        /// <returns></returns>
        public TaskBase FindTask(string taskName)
        {
            TaskBase task = null;
            mTaskDict.TryGetValue(taskName, out task);
            return task;
        }
    }
}
